using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Bll
{
	class CCoinHistoryManage
	{
		public static CCoinHistory CreateCoinHistory()
		{
           return  new CCoinHistory();
		}
	   
		public static CCoinHistory Save(CCoinHistory coinHistory)
	   {
			try
           {
				int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_AddCoinHistory", coinHistory.ID, coinHistory.coinNum, coinHistory.time, coinHistory.coinType, coinHistory.fromID, coinHistory.toID);
             
				if(0 == num)
                   return null;
                return coinHistory;
           }
           catch (Exception e)
           {
               return null;
           }
	   }
	   
	   public static bool Update(CCoinHistory coinHistory)
	   {
			try
			{
				int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_SaveCoinHistory", coinHistory.ID, coinHistory.coinNum, coinHistory.time, coinHistory.coinType, coinHistory.fromID, coinHistory.toID);
				if (0 == num)
                   return false;
				return true;
			}
			catch (Exception e)
			{
               return false;
			}
	   }
	   
	   public static bool Delete(CCoinHistory coinHistory)
	   {
			try
			{
				int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_RemoveCoinHistory", coinHistory.ID);
				if (0 == num)
                   return false;
				return true;
			}
			catch (Exception e)
			{
               return false;
			}
	   }
	   
	   static CCoinHistory GetAnswer(String ID)
	   {
			try
           {
               
               SqlDataReader reader= BLL.SqlHelper.ExecuteReader(CConnection.getConnString(), "sp_GetCoinHistory", ID);
               if (reader.NextResult())
               { 
					CCoinHistory coinHistory = new CCoinHistory();
					//coinHistory.coinNum = reader["coinNum"];
					//coinHistory.time = reader["time"];
					//coinHistory.coinType = reader["coinType"];
					coinHistory.fromID = reader["fromID"].ToString();
					coinHistory.toID = reader["toID"].ToString();
					
					reader.Close();
					return coinHistory;
               }
			   reader.Close();
               return null;
           }
           catch (Exception e)
           {

               //reader.Close();
               return null;
           }
	   }
	}
}